﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NextCMS.Models;

/// <summary>
/// Summary description for SitesHelper
/// </summary>
public class SitesHelper : ISite
{
    ISite sites = null;
	public SitesHelper()
	{
        sites=(ISite)NextCMS.DataAccess.Entities.CreateInstance<ISite>();
	}

    public SiteModel GetById(int Id)
    {
        return ApplicationCache.Sites.Where(c => c.Id == Id).FirstOrDefault();
    }

    public int Save(SiteModel page)
    {
        int id= sites.Save(page);
        ApplicationCache.Sites = null;
        return id;
    }

    public void Delete(int id)
    {
        sites.Delete(id);
        ApplicationCache.Sites = null;
    }

    public void Edit(SiteModel page)
    {
        sites.Edit(page);
        ApplicationCache.Sites = null;
    }

    public void Dispose()
    {
        sites.Dispose();
        sites = null;
    }

    public IEnumerable<SiteModel> GetAll()
    {
        return sites.GetAll();
    }


    public SiteModel GetByName(string SiteName)
    {
        return ApplicationCache.Sites.Where(c => c.Name == SiteName).FirstOrDefault();
    }
}